package com.tz.crm.entity;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Date;
import java.util.Set;

/**
 * 合同实体类
 */
@Entity
@Table(name = "tbl_contract")
@XmlRootElement
public class Contract extends BaseEntity {

    private static final long serialVersionUID = 381397960152691566L;
    private ContractTemplate contractTemplate;//模板
    private String inNum;//公司合同号n
    private String exNum;//客户定单号
    private String customerName;//公司名称
    private Date signDate;//签约日期
    private double amount;//金额
    private User signUser;//合约签署人
    private Date startDate;//合同起始日
    private Date endDate;//合同结束日
    private String remark;//备注
    private Set<Payment> payPlan;//付款计划
    private boolean isdistroy;//合同是否销毁
    private Set<PropertyValue> propertyValueSet;

    /**
     * 空参构造
     */
    public Contract() {
    }

    public Contract(ContractTemplate contractTemplate,String inNum,String exNum,String customerName,Date signDate,double amount,
                    User signUser,Date startDate,Date endDate,String remark){
        this.contractTemplate = contractTemplate;
        this.inNum = inNum;
        this.exNum = exNum;
        this.customerName = customerName;
        this.signDate = signDate;
        this.amount = amount;
        this.signUser = signUser;
        this.startDate = startDate;
        this.endDate = endDate;
        this.remark = remark;
    }

    @ManyToOne
    @JoinColumn(name = "contract_template_id")
    public ContractTemplate getContractTemplate() {
        return contractTemplate;
    }

    public void setContractTemplate(ContractTemplate contractTemplate) {
        this.contractTemplate = contractTemplate;
    }

    @Column(unique = true, nullable = false)
    public String getInNum() {
        return inNum;
    }

    public void setInNum(String inNum) {
        this.inNum = inNum;
    }

    public String getExNum() {
        return exNum;
    }

    public void setExNum(String exNum) {
        this.exNum = exNum;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public Date getSignDate() {
        return signDate;
    }

    public void setSignDate(Date signDate) {
        this.signDate = signDate;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    @ManyToOne
    @JoinColumn(name = "user_id")
    public User getSignUser() {
        return signUser;
    }

    public void setSignUser(User signUser) {
        this.signUser = signUser;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @OneToMany(mappedBy = "contract", cascade = {CascadeType.ALL})
    public Set<Payment> getPayPlan() {
        return payPlan;
    }

    public void setPayPlan(Set<Payment> payPlan) {
        this.payPlan = payPlan;
    }

    public boolean isIsdistroy() {
        return isdistroy;
    }

    public void setIsdistroy(boolean isdistroy) {
        this.isdistroy = isdistroy;
    }

    @OneToMany(mappedBy = "contract", cascade = {CascadeType.ALL})
    public Set<PropertyValue> getPropertyValueSet() {
        return propertyValueSet;
    }

    public void setPropertyValueSet(Set<PropertyValue> propertyValueSet) {
        this.propertyValueSet = propertyValueSet;
    }

    @Override
    public String toString() {
        return "Contract{" +
                "contractTemplate=" + contractTemplate +
                ", inNum='" + inNum + '\'' +
                ", exNum='" + exNum + '\'' +
                ", customerName='" + customerName + '\'' +
                ", signDate=" + signDate +
                ", amount=" + amount +
                ", signUser=" + signUser +
                ", startDate=" + startDate +
                ", endDate=" + endDate +
                ", remark='" + remark + '\'' +
                ", payPlan=" + payPlan +
                ", isdistroy=" + isdistroy +
                ", propertyValueSet=" + propertyValueSet +
                '}';
    }
}
